﻿<UserControl x:Class="BabyCloudDrives.DesktopApp.Controls.OAuth"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:ViewModels="clr-namespace:BabyCloudDrives.DesktopApp.ViewModels"
             xmlns:ControlUtility="clr-namespace:BabyCloudDrives.DesktopApp.Controls.Utilities"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:ViewModelBase="clr-namespace:BabyCloudDrives.DesktopApp.ViewModels.Base"
             xmlns:s="clr-namespace:BabyCloudDrives.DesktopApp.Utilities" mc:Ignorable="d" d:DesignHeight="620" d:DesignWidth="625">
    <UserControl.DataContext>
        <ViewModels:OAuthViewModel />
    </UserControl.DataContext>
    <UserControl.Style>
        <Style TargetType="UserControl">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=IsLoaded}" Value="True">
                    <Setter Property="Visibility" Value="Hidden" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Style>
    <Grid>
        <WebBrowser>
            <WebBrowser.Style>
                <Style TargetType="WebBrowser">
                    <Style.Triggers>
                        <DataTrigger
                            Binding="{Binding Path=AccessToken,Source={x:Static s:PresetValues.ResponseValue}}" Value="{x:Null}">
                            <Setter Property="ControlUtility:WebBrowserUtility.BindableSource"
                                    Value="{Binding Path=OAuthUri}" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=IsLoading}" Value="True">
                            <Setter Property="Visibility" Value="Hidden" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </WebBrowser.Style>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="LoadCompleted">
                    <ViewModelBase:InvokeDelegateCommandAction Command="{Binding Path=OnLoadCompleted}"
                                                               CommandParameter="{Binding RelativeSource={RelativeSource Self},Path=InvokeParameter}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </WebBrowser>
        <Label Background="#4C666638" Content="{Binding Path=LoadingMessage}" FontSize="24"
               HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
            <Label.Style>
                <Style TargetType="Label">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=IsLoading}" Value="True">
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=IsLoading}" Value="False">
                            <Setter Property="Visibility" Value="Hidden" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Label.Style>
        </Label>
    </Grid>
</UserControl>